package com.ruoyi.H5Send.demo;

import com.alibaba.fastjson.JSON;
import com.ruoyi.H5Send.model.request.SmsVariableRequest;
import com.ruoyi.H5Send.model.response.SmsVariableResponse;
import com.ruoyi.H5Send.util.ChuangLanSmsUtil;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;

import java.io.UnsupportedEncodingException;
import java.util.Map;

/**
 *
 * @author tianyh
 * @Description:变量短信发送
 */

@Component
public class SmsVariableSend {
    public static final String charset = "utf-8";
    // 用户平台API账号(非登录账号,示例:N1234567)
    public static String account = "N4865036";
    // 用户平台API密码(非登录密码)
    public static String pswd = "Tut1Bsv25m4aef";
    //请求地址请登录253云通讯自助通平台查看或者询问您的商务负责人获取
    public static String smsVariableRequestUrl = "https://smssh1.253.com/msg/variable/json";
    //短信内容
    public static  String msg = "【璞源探索】{$var}  正在对您发起背调，请点击链接  (http://192.168.3.235:8080/sq{$var})  进行授权";



    public  boolean sendLink(Map<String,String> map) {


   //        String msg = "【璞源探索】{$var}  正在对您发起背调，  {$var}  进行授权中";
        //参数组

        String phone = map.get("phone");
        String storeName = map.get("store");
        //阿里云文件后缀
        String webName = map.get("web");

//        String params = "13643669790,测试店铺,ISA754DASXCA";
        String params = phone+","+storeName+","+webName;
        //状态报告
        String report= "false";

        SmsVariableRequest smsVariableRequest=new SmsVariableRequest(account, pswd, msg, params, report);

        String requestJson = JSON.toJSONString(smsVariableRequest);

//        System.out.println("before request string is: " + requestJson);

        String response = ChuangLanSmsUtil.sendSmsByPost(smsVariableRequestUrl, requestJson);

//        System.out.println("response after request result is : " + response);

        SmsVariableResponse smsVariableResponse = JSON.parseObject(response, SmsVariableResponse.class);

//        System.out.println("response  toString is : " + smsVariableResponse);
        String code = smsVariableResponse.getCode();
        if (code.equals("0")) {
            return true;
        }
        else  {
            return false;
        }

    }
}
